package com.medusa.aps.business.modules.board.model;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 加工状态枚举
 *
 * @author 张治保
 * @since 2023/12/26
 */

@Getter
@RequiredArgsConstructor
public enum ProcessStatus {

    /**
     * 排队中
     */
    @Schema(description = "排队中")
    QUEUEING("排队中"),

    /**
     * 加工中
     */
    @Schema(description = "加工中")
    PROCESSING("加工中"),

    /**
     * 已完工
     */
    @Schema(description = "已完工")
    COMPLETED("已完工"),
    ;

    private final String name;

    /**
     * 计划状态
     *
     * @param planStartTime 计划开始时间
     * @param planEndTime   计划结束时间
     * @return 计划状态
     */
    public static ProcessStatus plan(LocalDateTime planStartTime, LocalDateTime planEndTime) {
        if (planStartTime == null || planEndTime == null) {
            return QUEUEING;
        }
        LocalDateTime now = LocalDateTime.now();
        return now.isBefore(planStartTime) ? QUEUEING : now.isAfter(planEndTime) ? COMPLETED : PROCESSING;
    }

    /**
     * 实际状态
     *
     * @return 实际状态
     */
    public static ProcessStatus real(BigDecimal planed, BigDecimal completed) {
        planed = planed == null ? BigDecimal.ZERO : planed;
        completed = completed == null ? BigDecimal.ZERO : completed;
        return completed.compareTo(planed) >= 0 ? COMPLETED : completed.compareTo(BigDecimal.ZERO) > 0 ? PROCESSING : QUEUEING;
    }


}
